<?php
/**
 * control 层父类
 * 
 * @copyright	http://www.easymvc.com
 * @author 		光哥 <439884988@qq.com>
 * @version		1.0 - 2012-07-02
 * @package		Lib
 */
if(!defined('EASYMVC')) {
	exit('Access Denied');
}

/**
 * 类Lib_Control
 */
class Lib_Control{

	public $tpl;
	public $request;
	public static $host;
	public static $domain;
	public static $config;
	public $isInitRequest;
	public $isajax;
	public $interface;
	public $param;
	
	public function __construct(){
		self::initConfig();
		//$this->initSmarty();
		$this->checkParam();
		if(!$this->isajax || !$this->interface)$this->initDiscuzTpl();
		if($this->isInitRequest) $this->initRequest();

	}
	public  function checkParam(){
		
	}
	public static function initConfig(){
		self::$config = Frame_Config::get('config');
		self::$host = self::$config['url'];
		self::$domain  = self::$config['domain'];
	}
	public function initRequest(){
		$this->request = Lib_Request::getInstance();
	}

	public function initDiscuzTpl(){
		$this->tpl = Lib_Extend_Discuz::getInstance();
		$this->tpl->assign('url',self::$host);
		$this->tpl->assign('alias',ALIAS);
		$this->tpl->assign('domain',self::$config['domain']);
		$this->tpl->assign('cssPath',self::$config['cssPath']);
		$this->tpl->assign('jsPath',self::$config['jsPath']);
		$this->tpl->assign('imagePath',self::$config['imagePath']);
		$this->tpl->assign('uploadPath',self::$config['uploadPath']);
		$this->tpl->assign('version',self::$config['version']);	
		
	}
	
	public function initSmarty(){
		$this->tpl = Lib_Extend_Smarty::getInstance();
		$this->tpl->assign('url',self::$host);
		$this->tpl->assign('cssPath',self::$config['cssPath']);
		$this->tpl->assign('jsPath',self::$config['jsPath']);
		$this->tpl->assign('imagePath',self::$config['imagePath']);
		$this->tpl->assign('uploadPath',self::$config['uploadPath']);
		$this->tpl->assign('version',self::$config['version']);
	}
  
   //上传文件
    public static function upload($filename,$folder,$fileType){
		$up = Lib_Upload::getInstance(); 
		if($folder){
			$up->uploadFolder = $folder;
		}else{
			$up->uploadFolder = APPPATH.slef::$config['url'];
		}
		if($fileType){
			$up->uploadFileType = $fileType;
		}else{
			$up->uploadFileType = 'file';
		}
		$result = $up->save($file_name);

		return $result;
    }
	public static function showJson($code,$msg,$data=array()){
		$return = array(
					'code'=>$code,
					'msg'=>$msg,
				);
		if($data) $return['data'] = $data;
		echo json_encode($return);
		exit;
	}
	public static function showMessage($msg,$url,$parent=''){
		header("Content-type: text/html; charset=utf-8");
		$url = Lib_Url::rewriteUrl($url);
		echo "<script>window.alert('{$msg}');window.{$parent}location.href='{$url}' </script>";
		exit;
	}
	
	public function __set($property,$value){
		$this->$property = $value;
	}
	public function __get($property){
		if(isset($this->$property))
		{
			return $this->$property;
		}else
		{
			return NULL;
		}
	}

}


?>